/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2013/05/12
* File: SceneNode.h
* Blog: http://www.cnblogs.com/zengqh/
**/

#pragma once

#include "enn_node.h"

namespace enn
{
class SceneGraph;
class OctreeNode;
class AreaOctree;
class SceneNode : public Node
{
	ENN_DECLARE_RTTI(SceneNode)
public:
	enum
	{
		DF_WORLD_AABB = 2,
		DF_OCTREE_POS = 3
	};

public:
	SceneNode();
	virtual ~SceneNode();

public:
	virtual void addChild( Node* node );

	const BoundingBox& getWorldAABB() const;

	const BoundingBox& getObjectAABB() const;

public:
	void setSceneGraph(SceneGraph* sg)
	{
		sg_ = sg;
	}

	SceneGraph* getSceneGraph() const
	{
		return sg_;
	}

	void setOctreeNode(OctreeNode* oc_node)
	{
		oc_node_ = oc_node;
	}

	OctreeNode* getOctreeNode() const
	{
		return oc_node_;
	}

public:
	virtual void addToRender()
	{

	}

protected:
	virtual void onSelfAdd();
	virtual void onSelfRemove();

	virtual void setSelfTransformDirty();
	virtual void setParentTransformDirty();

	virtual void update();

protected:
	virtual void setWorldAABBDirty();
	void setOctreePosDirty();

	virtual void checkUpdateWorldAABB();
	void checkUpdateOctreePos();
protected:
	SceneGraph*		sg_;
	OctreeNode*		oc_node_;
	BoundingBox		world_aabb_;
	BoundingBox		object_aabb_;
	AreaOctree*		area_;
};
}